﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Traceability.Repository
{
    /// <summary>
    /// 仓储接口
    /// </summary>
    /// <typeparam name="T">entity</typeparam>
    public interface IBaseRepository<T> where T : class
    {

        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns></returns>
        Task<IList<T>> GetAllAsync();

        /// <summary>
        /// 带参数查询所有数据
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<IList<T>> GetWhereAsync(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> InsertDataAsync(T entity);

        /// <summary>
        /// 获取单个对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<T> GetAsync(int id);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateDataAsync(T entity);

        /// <summary>
        /// 获取单个对象（根据条件）
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<T> GetAsync(Expression<Func<T, bool>> expression);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> DeleteDataAsync(T entity);


    }
}
